package com.example.administrator.wallet.adapter;

import android.content.Context;
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.wallet.R;
import com.example.administrator.wallet.model.bean.QuotationListBean;

import java.util.List;

/**
 * Effect:
 * <p>
 * Author:  CaiYapeng
 * <p>
 * Time  :  2018/7/18.
 */
public class QuotationAdapter extends BaseAdapter {
    private Context context;
    private List<QuotationListBean.DataBean> datas;

    public QuotationAdapter(FragmentActivity activity, List<QuotationListBean.DataBean> datas) {
        this.context = activity;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if(view==null){
            holder=new ViewHolder();
            view=View.inflate(context, R.layout.item_quotation_list,null);
            view.setTag(holder);
        }else {
            holder= (ViewHolder) view.getTag();
        }
        holder.title_master= (TextView) view.findViewById(R.id.title_master);
        holder.price= (TextView) view.findViewById(R.id.price);
        holder.count= (TextView) view.findViewById(R.id.count);
        holder.qushi= (Button) view.findViewById(R.id.btn_up_or_down_item_quotation_list);

        holder.title_master.setText(datas.get(i).getSymbol());
        holder.price.setText("¥"+datas.get(i).getCny());
        holder.count.setText("$"+datas.get(i).getUsd());
        holder.qushi.setText(datas.get(i).getRate());
        if(datas.get(i).getStatus().equals("+")){
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                holder.qushi.setBackground(context.getResources().getDrawable(R.drawable.quotation_but_jia));
            }
        }else{
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                holder.qushi.setBackground(context.getResources().getDrawable(R.drawable.quotation_but_jian));
            }
        }
        return view;
    }

    private class ViewHolder {
        private TextView title_master;
        private TextView price;
        private TextView count;
        private Button qushi;
    }
}
